'use strict'
module.exports = app => {
    const { STRING, INTEGER, DATE, ENUM } = app.Sequelize;
    // 配置（重要：一定要配置详细，一定要！！）
    const User = app.model.define('user', {
        id: {
            type: INTEGER(20).UNSIGNED,
            primaryKey: true,
            autoIncrement: true
        },
        username: {
            type: STRING(30),
            allowNull: false,
            defaultValue: '',
            comment: '用户名',
            unique: true
        },
        password: {
            type: STRING(200),
            allowNull: false,
            defaultValue: '',
            // 使用修改器模拟对密码加密
            set(val) {
                this.setDataValue('password', val + '888888');
            }
        },
        avatar_url: {
            type: STRING(200),
            allowNull: true,
            defaultValue: ''
        },
        sex: {
            type: ENUM,
            values: ['男', '女', '保密'],
            allowNull: true,
            defaultValue: '男',
            comment: '用户性别'
        },
        created_at: {
            type: DATE,
            // 使用获取器将日期转成时间戳
            get() {
                let createdAt = this.getDataValue('created_at')
                return (new Date(createdAt)).getTime()
            }
        },
        updated_at: DATE

    });
    return User;
};